package com.chaoyer.cynet.common.help;

import com.chaoyer.cynet.common.domain.ErrorInfo;
import com.chaoyer.cynet.common.exception.ValidateException;
import org.apache.commons.lang3.StringUtils;

/*
 * 校验帮助类
 * */
public class Assert {

    public static void check(boolean b, ErrorInfo errorInfo) throws ValidateException {
        if (!b) {
            error(errorInfo);
        }
    }

    public static void check(Object val, ErrorInfo errorInfo) throws ValidateException {
        if (null == val) {
            error(errorInfo);
        }
    }

    public static void check(String val, ErrorInfo errorInfo) throws ValidateException {
        if (StringUtils.isBlank(val)) {
            error(errorInfo);
        }
    }

    public static void checkInt(String val, ErrorInfo errorInfo) throws ValidateException {
        if (StringUtils.isBlank(val) || !StringUtils.isNumeric(val)) {
            error(errorInfo);
        }
    }

    public static void error(ErrorInfo errorInfo) throws ValidateException {
        throw new ValidateException(errorInfo);
    }

}